<template>
	<view class="">
		<image style="width: 100%;" src="https://mp-efee5dd1-84a8-4e86-a111-9bb95647d70d.cdn.bspapp.com/cloudstorage/d75bb795-9ef2-4c3a-acf9-ffeedf9d40e0.jpg" mode="widthFix"></image>
		<view class="img-box">
			<image  :src="serviceImg" mode="aspectFill"></image>
		</view>
		
		<button class="btn-box" @tap="codeTap">保存二维码</button>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				serviceImg:""
			}
		},
		onLoad() {
			var vipConfig = uni.getStorageSync('vipConfig')
			this.serviceImg = vipConfig.serviceImg
		},
		methods:{
			codeTap(){
				let USER_DATA_PATH =  tt.getEnvInfoSync().common.USER_DATA_PATH
				uni.showLoading({
					title: "下载中..."
				})
				var that = this
				uni.downloadFile({
					url: this.serviceImg,
					filePath: USER_DATA_PATH + '/' + new Date().getTime() + '.png',
					success: (res) => {
						var benUrl = res.filePath
						//图片保存到本地相册
						uni.saveImageToPhotosAlbum({
							filePath: benUrl,
							//授权成功，保存图片
							success: function(data) {
								uni.hideLoading()
								uni.showToast({
									title: "下载成功"
								})
							},
							//授权失败
							fail: function(err) {
								if (err.errMsg) {
									//重新授权弹框确认
									uni.showModal({
										title: '温馨提示',
										content: '授权失败，请稍后重新获取',
										showCancel: false
									});
				
								}
								uni.hideLoading()
							}
						});
				
				
				
					},
					fail: (error) => {
						console.log(error)
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.btn-box{
		position: fixed;
		left: 50%;
		bottom: 20rpx;
		transform: translateX(-50%);
	}
	.img-box{
		image{
			width: 300rpx;
			height: 300rpx;
			position: absolute;
			top: 1550rpx;
			left: 50%;
			transform: translateX(-50%);
		}
	}
</style>